
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>如何在 Spring Boot 中定义和读取自定义配置？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>如何在 Spring Boot 中定义和读取自定义配置？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">在Spring Boot中，如何以结构化和类型安全的方式管理自定义配置？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过创建一个配置类，并使用 `@ConfigurationProperties` 注解将其与配置文件中的属性进行映射。这种方式可以将相关的配置属性聚合到一个Java对象中，从而实现结构化和类型安全的管理。</div>
          </div>
          <div class="card-source">来源: 1.2 使用自定义配置类</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">Spring Boot中的 `@Value` 注解有什么作用？请举例说明其使用语法。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`@Value` 注解用于将配置文件中的单个属性值直接注入到 Spring Bean 的字段中。其语法通常使用 `${...}`占位符，例如：`@Value("${myapp.custom.property}")`。</div>
          </div>
          <div class="card-source">来源: 2.1 使用 @Value 注解</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">除了使用注解，还有哪种方式可以在Spring Boot中动态地读取配置属性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">可以通过注入 `Environment` 对象来动态读取配置。`Environment` 实例提供了 `getProperty()` 方法，允许在运行时根据属性键（key）获取其对应的值。</div>
          </div>
          <div class="card-source">来源: 2.2 使用 Environment 对象</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">Spring Boot默认支持哪两种格式的配置文件来定义自定义属性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Spring Boot默认支持 `application.properties` 和 `application.yml` 这两种格式的配置文件。</div>
          </div>
          <div class="card-source">来源: 1.1 使用 application.properties 或 application.yml</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">在Spring Boot中，配置加载的优先级是怎样的？哪种配置源的优先级最高？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Spring Boot按照特定的顺序加载配置，高优先级的配置会覆盖低优先级的配置。根据文档，命令行参数（Command Line Properties）具有最高的加载优先级。</div>
          </div>
          <div class="card-source">来源: 3. 配置文件的加载优先级</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">请按从高到低的顺序列出Spring Boot中三种常见外部化配置的优先级。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">根据文档，从高到低的优先级顺序为：<br>1. 命令行参数 (Command Line Properties)<br>2. Java 系统属性 (Java System Properties)<br>3. 操作系统环境变量 (OS Environment Variables)</div>
          </div>
          <div class="card-source">来源: 3. 配置文件的加载优先级</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
